home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 12 / Example 12.6 / effect.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-01  |  2.4 KB  |  111 lines

  1. #ifndef RTS_EFFECT
  2. #define RTS_EFFECT
  3.  
  4. #include <windows.h>
  5. #include <d3dx9.h>
  6. #include <vector>
  7. #include "debug.h"
  8. #include "shader.h"
  9. #include "skinnedmesh.h"
  10.  
  11. void LoadEffectResources(IDirect3DDevice9 *m_pDevice);
  12. void UnloadEffectResources();
  13.  
  14. //Transform Help structure
  15. struct TRANSFORM
  16. {
  17.     TRANSFORM();
  18.     TRANSFORM(D3DXVECTOR3 _pos);
  19.     TRANSFORM(D3DXVECTOR3 _pos, D3DXVECTOR3 _rot);
  20.     TRANSFORM(D3DXVECTOR3 _pos, D3DXVECTOR3 _rot, D3DXVECTOR3 _sca);
  21.  
  22.     void Init(D3DXVECTOR3 _pos);
  23.     void Init(D3DXVECTOR3 _pos, D3DXVECTOR3 _rot);
  24.     void Init(D3DXVECTOR3 _pos, D3DXVECTOR3 _rot, D3DXVECTOR3 _sca);
  25.  
  26.     D3DXMATRIX GetWorldMatrix();
  27.  
  28.     D3DXVECTOR3 m_pos, m_rot, m_sca;    
  29. };
  30.  
  31. //Virtual EFFECT class...
  32. class EFFECT
  33. {
  34.     public:
  35.         EFFECT(IDirect3DDevice9 *Dev);
  36.         ~EFFECT(){}
  37.         virtual void Update(float timeDelta) = 0;
  38.         virtual void Render() = 0;
  39.         virtual bool isDead() = 0;
  40.  
  41.         void PreRender();
  42.         void PostRender();
  43.  
  44.         float m_time;
  45.         IDirect3DDevice9 *m_pDevice;
  46.         D3DXVECTOR4 m_color;
  47. };
  48.  
  49. class EFFECT_SPELL : public EFFECT
  50. {
  51.     public:
  52.         EFFECT_SPELL(IDirect3DDevice9 *Dev, D3DXVECTOR3 _pos);
  53.         void Update(float timeDelta);
  54.         void Render();
  55.         bool isDead();
  56.  
  57.     private:
  58.         TRANSFORM m_t1;
  59.         TRANSFORM m_c[10];
  60. };
  61.  
  62. class EFFECT_FIREBALL : public EFFECT
  63. {
  64.     public:
  65.         EFFECT_FIREBALL(IDirect3DDevice9 *Dev, BONE *_src, D3DXVECTOR3 _dest);
  66.         void Update(float timeDelta);
  67.         void Render();
  68.         bool isDead();
  69.         D3DXVECTOR3 GetPosition(float prc);
  70.  
  71.     private:
  72.         BONE *m_pSrcBone;
  73.         float m_speed, m_length, m_prc;
  74.         D3DXVECTOR3 origin, dest;
  75.         TRANSFORM m_t1;
  76. };
  77.  
  78. class EFFECT_LENSFLARE : public EFFECT
  79. {
  80.     public:
  81.  
  82.         struct FLARE
  83.         {
  84.             FLARE(D3DXCOLOR _color, float _place, float _scale, int _sourceFlare)
  85.             {
  86.                 m_color = _color;
  87.                 place = _place;
  88.                 scale = _scale;
  89.                 sourceFlare = _sourceFlare;
  90.             }
  91.  
  92.             D3DXCOLOR m_color;    //Flare m_color
  93.             float place;        //position along the ray
  94.             float scale;        //Size of the flare
  95.             int sourceFlare;    //Which flare from the texture to use
  96.         };
  97.  
  98.         EFFECT_LENSFLARE(IDirect3DDevice9 *Dev, int _type, D3DXVECTOR3 _position);
  99.         void Update(float timeDelta);
  100.         void Render();
  101.         bool isDead();
  102.  
  103.     private:
  104.         float m_mainAlpha;            //Overall alpha
  105.         bool m_inScreen;                //Inside screen bounds or not
  106.         int m_type;                    //Flare type
  107.         D3DXVECTOR3 m_position;        //World position of light source
  108.         std::vector<FLARE> m_flares;    //Array of flares
  109. };
  110.  
  111. #endif